package com.heima;

import java.util.ArrayList;
import java.util.Random;

public class TestStudent {
    public static void main(String[] args) {
        //随机数
        Random r = new Random();
        Student stu01 = new Student("张一", r.nextInt(16, 23), "语文");
        Student stu02 = new Student("张二", r.nextInt(16, 23), "数学");
        Student stu03 = new Student("张三", r.nextInt(16, 23), "英语");
        Student stu04 = new Student("张四", r.nextInt(16, 23), "物理");
        Student stu05 = new Student("张五", r.nextInt(16, 23), "化学");
        Student stu06 = new Student("张六", r.nextInt(16, 23), "生物");
        ArrayList<Student> list = new ArrayList<>();
        list.add(stu01);
        list.add(stu02);
        list.add(stu03);
        list.add(stu04);
        list.add(stu05);
        list.add(stu06);
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() + " " + stu.getAge() + " " + stu.getMajority());
        }
        System.out.println("------------------");
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            if (stu.getAge() < 18) {
                stu.setMajority("计算机");
            }
        }
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() + " " + stu.getAge() + " " + stu.getMajority());
        }
        System.out.println("------------------");
        //计数器，记录年龄是偶数的学生个数
        int count = 0;
        for (int j = 0; j < list.size(); j++) {
            Student stu = list.get(j);
            if (count == 2) {
                break;
            }
            if (stu.getAge() % 2 == 0) {
                list.remove(j);
                count++;
            }
        }
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() + " " + stu.getAge() + " " + stu.getMajority());
        }
        System.out.println("------------------");
        int minAge = list.get(0).getAge();
        int index = 0;
        for (int k = 0; k < list.size(); k++) {
            Student stu = list.get(k);
            if (minAge > stu.getAge()) {
                minAge = stu.getAge();
                 index = k;
                break;
            }
        }
        Student stu1 = list.get(index);
        stu1.setMajority("行政管理");
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() + " " + stu.getAge() + " " + stu.getMajority());
        }
    }
}

